# 随机
# The guess API is already defined for you.
# @param num, your guess
# @return -1 if num is higher than the picked number
#          1 if num is lower than the picked number
#          otherwise return 0
# def guess(num: int) -> int:

class Solution:
    def guessNumber(self, n: int) -> int:
        pick = randint(1, n)
        while guess(pick) != 0:
            if guess(pick) == -1:
                pick = randint(1, pick)
            elif guess(pick) == 1:
                pick = randint(pick, n)
        return pick


# 二分查找
# The guess API is already defined for you.
# @param num, your guess
# @return -1 if num is higher than the picked number
#          1 if num is lower than the picked number
#          otherwise return 0
# def guess(num: int) -> int:

class Solution:
    def guessNumber(self, n: int) -> int:
        left, right = 1, n 
        pick = (left + right) // 2
        while guess(pick) != 0:
            if guess(pick) == -1:
                right = pick - 1
            elif guess(pick) == 1:
                left = pick + 1
            pick = (left + right) // 2
        return pick